package club.weiyuanstudio.android.app.demo

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.widget.Button
import android.widget.TextView
import android.widget.Toast
import club.weiyuanstudio.android.app.demo.experiment.ex3.Activity

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val btn = findViewById<Button>(R.id.button)
        btn.setOnClickListener(fun(_) {
            val textShow = findViewById<TextView>(R.id.textShow)
            textShow.text = "Hello Android!"
        })

        val toastBtn = findViewById<Button>(R.id.button2)
        toastBtn.setOnClickListener(fun(_) {
            Toast.makeText(this, "SHOW TOAST", Toast.LENGTH_LONG).show()
        })

        val goEx3Btn = findViewById<Button>(R.id.button3)
        goEx3Btn.setOnClickListener(fun(_) {
            val i = Intent(this, Activity::class.java)
            startActivity(i)
        })
    }

    override fun onCreateOptionsMenu(menu: Menu?): Boolean {
        menuInflater.inflate(R.menu.main, menu)
        return super.onCreateOptionsMenu(menu)
    }

    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        when (item.itemId) {
            R.id.menuItem1 -> findViewById<TextView>(R.id.textShow).text = "MENU ITEM 1"
            R.id.menuItem2 -> findViewById<TextView>(R.id.textShow).text = "MENU ITEM 2"
        }

        return super.onOptionsItemSelected(item)
    }
}
